package com.itheima.day5;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Map;

@WebServlet("/servlet004")
public class DemoServlet04 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //根据名称获取数据
        String username = req.getParameter("name");
        String password = req.getParameter("pass");
        System.out.println(username);
        System.out.println(password);
        System.out.println("--------");
        //根据名称获取所有数据
        String[] hobbies = req.getParameterValues("hobby");
        for (String s : hobbies) {
            System.out.println(s);
        }
        System.out.println("--------");
        //获取所有名称
        Enumeration<String> parameterNames = req.getParameterNames();
        while (parameterNames.hasMoreElements()) {
            String name = parameterNames.nextElement();
            System.out.println(name);
        }
        System.out.println("-----------");
        Map<String, String[]> parameterMap = req.getParameterMap();
        for (String key : parameterMap.keySet()) {
            String[] value = parameterMap.get(key);
            for (String values : value) {
                System.out.println(key + ":" + values);
            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
